package com.lzh.crm.service.impl;

import com.lzh.crm.mapper.ServicesMapper;
import com.lzh.crm.pojo.Services;
import com.lzh.crm.pojo.ServicesDTO;
import com.lzh.crm.pojo.User;
import com.lzh.crm.service.ServicesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ServicesServiceImpl implements ServicesService {
    @Autowired
    private ServicesMapper servicesMapper;

    @Override
    public void insert(Services services) {
        servicesMapper.insert(services);
    }

    @Override
    public void delete(Integer serId) {
        servicesMapper.delete(serId);
    }

    @Override
    public void update(Services services) {
        servicesMapper.update(services);
    }

    @Override
    public List<ServicesDTO> selectAll() {
        return servicesMapper.selectAll();
    }

    @Override
    public List<ServicesDTO> selectNeed(Services services) {
        return servicesMapper.selectNeed(services);
    }

    @Override
    public List<Services> select() {
        return servicesMapper.select();
    }

    @Override
    public List<Services> convertExcelDTOToServices(List<Services> dtoList) {
        return dtoList.stream().map(dto -> {
            Services ser = new Services();
            ser.setUserId(dto.getUserId());
            ser.setStyle(dto.getStyle());
            ser.setStatus(dto.getStatus());
            return ser;
        }).collect(Collectors.toList());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveBatch(List<Services> serList) {
        servicesMapper.saveBatch(serList);
    }

    @Override
    public List<Services> selectId(String userId) {
        return servicesMapper.selectId(userId);
    }
}
